package com.bjkcst.baselib.modbus;

import com.serotonin.modbus4j.BasicProcessImage;
import com.serotonin.modbus4j.ip.tcp.TcpSlave;

public class ModbusSlaver {

    private BasicProcessImage mProcessImage;

    private static ModbusSlaver mInstance = null;

    /*** 私有化构造方法 */
    private ModbusSlaver() {

    }

    public static ModbusSlaver getInstance() {
        if (null == mInstance) {
            mInstance = new ModbusSlaver();
        }
        return mInstance;
    }

    public void createModbusSlave() throws Exception {
        convertOpcToModbus();
        covertModbusToOpc();


        mProcessImage = new BasicProcessImage(1);
        TcpSlave tcpSlave = new TcpSlave(9800, false);
        tcpSlave.addProcessImage(mProcessImage);
        tcpSlave.start();
    }

    public void setRegisters(int offset, short[] shorts) {
        if (null != mProcessImage) {
            mProcessImage.setHoldingRegister(offset, shorts);
        }
    }

    public void covertModbusToOpc() throws Exception {

    }

    public void convertOpcToModbus() {

    }
}
